package com.nine.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nine.entity.RolePermission;
import com.nine.service.RolePermissionService;

@Controller
public class RolePermissionController {
	
	@Autowired
	private RolePermissionService rolePermissionService;
	
	
	//批量授权
	@RequestMapping("insertMoreRolePermission")
	@ResponseBody
	public Integer insertMoreRolePermission(String ids,Integer roleId) {
		
		List<RolePermission> rolePermissions=null;
		String[] split = ids.split(",");
		if(split.length>0) {
			rolePermissions=new ArrayList<RolePermission>();
			for (String permissionId : split) {
				RolePermission p=new RolePermission();
				p.setId(null);
				p.setPermissionId(new Integer(permissionId));
				p.setRoleId(roleId);
				rolePermissions.add(p);
			}
		}
		Integer result = rolePermissionService.insertMore(rolePermissions);
		
		return result;	
	}
	
	
	
	//批量删除角色权限
	@ResponseBody
	@RequestMapping("delMoreRolePermission")
	public Integer delMoreRolePermission(String ids,Integer roleId) {
		String[] split = ids.split(",");
		Integer[] ss=new Integer[split.length];
		for (int i = 0; i < split.length; i++) {
			ss[i]=new Integer(split[i]);	
		}
		
		if(ss.length>0) {
			Integer result = rolePermissionService.delMoreRolePermission(ss, roleId);
			return result;
		}
			return null;
	}
	
	
}
